package cn.wolfcode.cloud.shop.advice;


import cn.wolfcode.cloud.shop.exception.BusinessException;
import cn.wolfcode.cloud.shop.resp.CodeMsg;
import cn.wolfcode.cloud.shop.resp.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;

/**
 * @author Administrator
 */
public class CommonExceptionAdvice {


    private final Logger logger = LoggerFactory.getLogger("COMMON_EXCEPTION_ADVICE");

    @ExceptionHandler(Exception.class)
    public Result<?> serverExceptionHandler(Exception e){
        logger.error("服务器异常:",e);
        return Result.error(CodeMsg.DEFAULT_SERVER_ERROR);
    }

    @ExceptionHandler(BusinessException.class)
    public Result<?> businessExceptionHandler(BusinessException e){
        logger.error("业务异常:",e);
        return Result.error(e.getCodeMsg());
    }


}
